package huixue.cn.com.rxapp.rx;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import butterknife.BindView;
import butterknife.OnClick;
import huixue.cn.com.rxapp.R;
import huixue.cn.com.rxapp.base.SimpleActivity;

public class AnimatorActivity extends SimpleActivity {

    @BindView(R.id.btn1)
    Button btn1;

    @BindView(R.id.btn2)
    Button btn2;

    @BindView(R.id.iv_img)
    ImageView img;

    @Override
    public int getLayout() {
        return R.layout.activity_animator;
    }

    @Override
    public void initView() {

    }

    @Override
    public void addEvent() {

    }

    @OnClick({R.id.btn1,R.id.btn2})
    public void onViewClicked(View view) {
        if(view.getId()==R.id.btn1){
            PropertyValuesHolder p1 = PropertyValuesHolder.ofFloat("rotation",0f,360f);

            PropertyValuesHolder p2 = PropertyValuesHolder.ofFloat("translationX",0f,200f);

            PropertyValuesHolder p3 = PropertyValuesHolder.ofFloat("translationY",0f,200f);

            ObjectAnimator.ofPropertyValuesHolder(img,p1,p2,p3).setDuration(2000L).start();
        }else if(view.getId()==R.id.btn2){
            ObjectAnimator a1 = ObjectAnimator.ofFloat(img,"rotation",0f,360f);
            ObjectAnimator a2 = ObjectAnimator.ofFloat(img,"translationX",0f,360f);
            ObjectAnimator a3 = ObjectAnimator.ofFloat(img,"translationY",0f,360f);
            ObjectAnimator a4 = ObjectAnimator.ofFloat(img,"alpha",0f,1f);

            AnimatorSet set = new AnimatorSet();
            set.play(a1).before(a2).after(a3).after(a4);
            set.setDuration(2000L);
            set.start();

        }


    }

}
